package com.zee.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import com.zee.adapter.ZxBannerAdapter;
import com.zee.base.BaseZAdapter;
import com.zee.recyclerview.RefreshAndLoadMoreManager;
import com.zee.recyclerview.XRecyclerView;
import com.zee.utils.UIUtils;


/**
 * @author Administrator
 */
public class ZxRecyclerView extends XRecyclerView {

    public ZxRecyclerView(Context context) {
        super(context);
    }

    public ZxRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ZxRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public View addFootEmptyView(int dpValue) {
        View view = getEmptyView(dpValue);
        addFooterView(view);
        return view;
    }

    public View addHeadEmptyView(int dpValue) {
        View view = getEmptyView(dpValue);
        addHeaderView(view);
        return view;
    }

    private View getEmptyView(int dpValue) {
        RefreshAndLoadMoreManager refreshAndLoadMoreManager = getRefreshAndLoadMoreManager();

        View textView = new View(getContext());
//        textView.setBackgroundColor(Color.parseColor("#ff000000"));

        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, UIUtils.dpToPx(dpValue));
        if (refreshAndLoadMoreManager.getLinearLayoutManagerOrientation() == 1) {
            layoutParams = new ViewGroup.LayoutParams(UIUtils.dpToPx(dpValue), ViewGroup.LayoutParams.MATCH_PARENT);
        }
        textView.setLayoutParams(layoutParams);
        return textView;
    }

    /**
     * 将BannView添加到头部
     *
     * @param dpValue
     * @param bannerAdapter
     * @return
     */
    private ZxBannerView addBannerViewToHead(int dpValue, ZxBannerAdapter bannerAdapter) {
        ZxBannerView bannerView = new ZxBannerView(getContext());
        RefreshAndLoadMoreManager refreshAndLoadMoreManager = getRefreshAndLoadMoreManager();
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, UIUtils.dpToPx(dpValue));
        if (refreshAndLoadMoreManager.getLinearLayoutManagerOrientation() == 1) {
            layoutParams = new ViewGroup.LayoutParams(UIUtils.dpToPx(dpValue), ViewGroup.LayoutParams.MATCH_PARENT);
        }

        bannerView.setLayoutParams(layoutParams);
        bannerView.setBannerAdapter(bannerAdapter);
        addHeaderView(bannerView);
        return bannerView;
    }
}
